from itertools import count

# 目的：根据一定的下标范围，去获取对应下标处的元素
# 格式：列表[start:stop:step]
# 说明：1）默认值[0:len(列表):1]
#     2)参数可以省，但是冒号不能省  eg：[::]
#     3）范围：[start,stop) 左包右不包
#     4）切片可以支持所有有序序列：元组、列表、字符串
#     5）del 删除切片数据

ls = [5,6,7,'lucy',8,9,"lily"]
# print(ls[2])
# print(ls[1:4:1],ls[::1])
# print(ls[:4:1])
# print(ls[::1])
# print(ls[::])
# print(ls[6:0:-1])
# print(ls[::-1]) #反向遍历
# del ls[1:4:1]
# print(ls)

# for l in ls:
#     print(l,"~~~",end=",",sep="")
# #
# for index in range(len(ls)):
#     print(ls[index], "--", end=",", sep="")
#
# for i in range(len(ls)-1,-1,-1):   #反向遍历
#     print(ls[i])
# 判断列表是否含有某个元素 判断字符串是否含有某个字符
# a=[1,2,3,4,5,6,7,8,9]
# x=int(input('输入'))
# if x in a:
#     print("True")
# else:
#     print("False")

str1 = "aslkdgja"
print("dg" in str1)

# 将列表中长度大于3的元素删除
a=["fatd","yduafs","rfs","syf","ysds"]
for index in range(len(a)-1,-1,-1):
    if len(a[index]) >3:
        del a[index]
print(a)


# 各个个元素出现的次数
a=[1,2,3,3,2,1,1,2,3,4,5,6,7,1]
print(a.count(1))
# 计算列表中所有偶数的和
a=[1,2,3,3,2,1,1,2,3,4,5,6,7,1]
sum=0
for i in a:
    if i%2==0:
       sum += i
print(sum)
# 找出列表中的第二大数值
# 排序找
a = [4,1,5,678,34,8,12,45,5,4]
a.sort()
print(a[-2])# 默认升序
# 找出列表中的最大数值 不通过排序
ls6 = [52,64,71,8,31,44,51,5]
max1=ls6[0]
for i in ls6[1::]:
    if i > max1:
        max1=i
print(max1)
a = [4,1,5,678,34,8,12,45,5,4]
a.sort()
print(a[-1])
# 定义一个变量，代表最大值，初始值为第一个数


